package com.rajaev.dtu.tractor.interfaces;


import com.rajaev.dtu.tractor.app.service.RoleService;
import com.rajaev.dtu.tractor.app.service.UserService;
import com.rajaev.dtu.tractor.domain.vo.ResourceVo;
import com.rajaev.dtu.tractor.domain.vo.RoleVo;
import com.rajaev.dtu.tractor.infrastructure.base.errors.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
public class RoleController  {

    @Autowired
    RoleService roleService;

    @Autowired
    UserService userService;


    @PostMapping("/role/add")
    public void addRole(@RequestBody RoleVo roleVo) throws BusinessException {
        roleService.insertRole(roleVo);
    }

    @PostMapping("/role/edit")
    public void editRole(@RequestBody RoleVo roleVo) throws BusinessException {
        roleService.updateRole(roleVo);
    }

    @PostMapping("/role/delete")
    public void deleteRole(@NotNull Integer roleId){
        roleService.deleteRole(roleId);
    }

    @GetMapping("/role/getList")
    public List<RoleVo> getRoles(){
       return roleService.selectRoles();
    }


    @GetMapping("/role/getAllResource")
    public List<ResourceVo> selectAllResource(){
        return roleService.selectAllResource();
    }


}
